home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr47 / ucrasm27.zip / TEST.ZIP / FCMP.ASM next >
Assembly Source File  |  1992-04-17  |  4KB  |  228 lines

  1.         .xlist
  2.         include     stdlib.a
  3.         includelib    stdlib.lib
  4.         .list
  5.  
  6. ; Global variables go here:
  7.  
  8. dseg        segment    para public 'data'
  9. Name1        dd    ?
  10. Name2        dd    ?
  11. Handle1        dw    ?
  12. Handle2        dw    ?
  13. LineCnt        dw    0
  14. Index1        db    0,0
  15. Index2        db    0,0
  16. Cnt1        db    0
  17. Cnt2        db    0
  18. Buffer1        db    256 dup (0)
  19. Buffer2        db    256 dup (0)
  20. dseg        ends
  21.  
  22. wp        equ    <word ptr>
  23.  
  24.  
  25. cseg        segment    para public 'code'
  26.         assume    cs:cseg, ds:dseg
  27.  
  28. ;
  29. ; Variables that wind up being used by the standard library routines.
  30. ; The MemInit routine uses "PSP" and "zzzzzzseg" labels.  They must be
  31. ; present if you intend to use getenv, MemInit, malloc, and free.
  32. ;
  33. ;
  34.         public    PSP
  35. PSP        dw    ?
  36. ;
  37. ;
  38. ; Error- Prints a DOS error message depending upon the error type.
  39. ;
  40. Error        proc    near
  41.         cmp    ax, 2
  42.         jne    NotFNF
  43.         print
  44.         db    "File not found",0
  45.         jmp    ErrorDone
  46.  
  47. NotFNF:        cmp    ax, 4
  48.         jne    NotTMF
  49.         print
  50.         db    "Too many open files",0
  51.         jmp    ErrorDone
  52.  
  53. NotTMF:        cmp    ax, 5
  54.         jne    NotAD
  55.         print
  56.         db    "Access denied",0
  57.         jmp    ErrorDone
  58.  
  59. NotAD:        cmp    ax, 12
  60.         jne    NotIA
  61.         print
  62.         db    "Invalid access",0
  63.         jmp    ErrorDone
  64.  
  65. NotIA:
  66. ErrorDone:    putcr
  67.         ret
  68. Error        endp
  69.  
  70.  
  71.  
  72.  
  73. ;-----------------------------------------------------------------
  74. ; Main is the main program.  Program execution always begins here.
  75. ;
  76. Main        proc
  77.         mov    cs:PSP, es        ;Save pgm seg prefix
  78.         mov    ax, seg dseg        ;Set up the segment registers
  79.         mov    ds, ax
  80.         mov    es, ax
  81. ;
  82.         mov    dx, 0
  83.         meminit
  84.         jnc    GoodMemInit
  85.  
  86.         print
  87.         db    "Error initializing memory manager",cr,lf,0
  88.         jmp    Quit
  89. GoodMemInit:
  90.  
  91. ; File comparison routine.  First, open the two source files.
  92.  
  93.         argc
  94.         cmp    cx, 2        ;Do we have two filenames?
  95.         je    GotTwoNames
  96.         print
  97.         db    "Usage: fcmp file1 file2",cr,lf,0
  98.         jmp    Quit
  99.  
  100. GotTwoNames:    mov    ax, 1        ;Get first file name
  101.         argv
  102.         mov    wp Name1, di
  103.         mov    wp Name1+2, es
  104.  
  105. ; Open the files by calling DOS.
  106.  
  107.         mov    ax, 3d00h    ;Open for reading
  108.         lds    dx, Name1
  109.         int    21h
  110.         jnc    GoodOpen1
  111.         printf
  112.         db    "Error opening %^s:",0
  113.         dd    Name1
  114.         call    Error
  115.         jmp    Quit
  116.  
  117. GoodOpen1:    mov    dx, dseg
  118.         mov    ds, dx
  119.         mov    Handle1, ax
  120.  
  121.         mov    ax, 2        ;Get first file name
  122.         argv
  123.         mov    wp Name2, di
  124.         mov    wp Name2+2, es
  125.  
  126.         mov    ax, 3d00h    ;Open for reading
  127.         lds    dx, Name2
  128.         int    21h
  129.         jnc    GoodOpen2
  130.         printf
  131.         db    "Error opening %^s:",0
  132.         dd    Name2
  133.         call    Error
  134.         jmp    Quit
  135.  
  136. GoodOpen2:    mov    dx, dseg
  137.         mov    ds, dx
  138.         mov    Handle2, ax
  139.  
  140. ; Read the data from the files and compare it.
  141.  
  142.         mov    LineCnt, 1
  143. CmpLoop:    mov    bx, Handle1
  144.         mov    cx, 256
  145.         lea    dx, Buffer1
  146.         mov    ah, 3fh
  147.         int    21h
  148.         jc    FileError
  149.         cmp    ax, 256
  150.         jne    EndOfFile
  151.  
  152.         mov    bx, Handle2
  153.         mov    cx, 256
  154.         lea    dx, Buffer2
  155.         mov    ah, 3fh
  156.         int    21h
  157.         jc    FileError
  158.         cmp    ax, 256
  159.         jne    BadLen
  160.         mov    ax, dseg
  161.         mov    ds, ax
  162.         mov    es, ax
  163.         mov    cx, 256
  164.         lea    di, Buffer1
  165.         lea    si, Buffer2
  166.         cld
  167.     repe    cmpsb
  168.         jne    BadCmp
  169.         jmp    CmpLoop
  170.  
  171.  
  172. FileError:    print
  173.         db    "Error reading files: ",0
  174.         call    Error
  175.         jmp    Quit
  176.  
  177.  
  178. BadLen:        print
  179.         db    "File lengths were different",cr,lf,0
  180.  
  181. BadCmp:        print
  182.         db      7,"Files were not equal",cr,lf,0
  183.         mov    ax, 4c01h
  184.         int    21h
  185.  
  186.  
  187. EndOfFile:    push    ax            ;Save final length.
  188.         mov    bx, Handle2
  189.         mov    cx, 256
  190.         lea    dx, Buffer2
  191.         mov    ah, 3fh
  192.         int    21h
  193.         jc    BadCmp
  194.         pop    bx
  195.         cmp    ax, bx
  196.         jne    BadLen
  197.  
  198.         mov    cx, ax
  199.         mov    ax, dseg
  200.         mov    ds, ax
  201.         mov    es, ax
  202.         lea    di, Buffer2
  203.         lea    si, Buffer1
  204.     repe    cmpsb
  205.         jne    BadCmp
  206.  
  207. Quit:        mov    ax, 4c00h        ;Set Exit code to okay.
  208.         int    21h
  209. Main        endp
  210.  
  211. cseg            ends
  212.  
  213.  
  214.  
  215. ; Allocate a reasonable amount of space for the stack (2k).
  216.  
  217. sseg        segment    para stack 'stack'
  218. stk        db    256 dup ("stack   ")
  219. sseg        ends
  220.  
  221.  
  222. ; zzzzzzseg must be the last segment that gets loaded into memory!
  223.  
  224. zzzzzzseg    segment    para public 'zzzzzz'
  225. LastBytes    db    16 dup (?)
  226. zzzzzzseg    ends
  227.         end    Main
  228.